home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / C⁄C++ / Marathon Map Viewer / @Source / chunkStorage.cpp next >
Text File  |  1995-06-05  |  1KB  |  47 lines

  1. /*-----------------------------------------------------------------
  2. -----------------------------------------------------------------*/
  3. #include "chunkStorage.h"
  4.  
  5. /*-----------------------------------------------------------------
  6.     Reads in the requested chunk and returns a ptr to it.
  7.     Assumes next chunk offset for last chunk is 0;
  8. -----------------------------------------------------------------*/
  9. Ptr readChunk(short fileRefNum, long type, levelInfo *theLevelInfo, short levelNum)
  10.     {
  11.     long        levelOffset = theLevelInfo[levelNum].offset;
  12.     long        levelSize = theLevelInfo[levelNum].size;
  13.     chunkHeader    theChunk;
  14.     long        count;
  15.     Ptr            chunkData = nil;
  16.  
  17.     SetFPos(fileRefNum, fsFromStart, levelOffset);
  18.  
  19.     do    {
  20.         count = sizeof(chunkHeader);
  21.         ThrowIfOSErr_(FSRead(fileRefNum, &count, &theChunk));
  22.         if (theChunk.chunkType == type)
  23.             {
  24.             count = theChunk.size;
  25.             chunkData = NewPtrClear(count);    // could fail I suppose
  26.             if (chunkData)
  27.                 ThrowIfOSErr_(FSRead(fileRefNum, &count, chunkData));
  28.             break;
  29.             }
  30.         SetFPos(fileRefNum, fsFromStart, levelOffset + theChunk.nextChunk);
  31.         } while (theChunk.nextChunk);
  32.     return chunkData;
  33.     }
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.